<?php
// 管理抽奖活动
namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Lottery extends Model
{
    use HasFactory;

    protected $fillable = [
        'name',
        'description',
        'start_time',
        'end_time',
        'status',
    ];

    protected $casts = [
        'start_time' => 'datetime',
        'end_time' => 'datetime',
        'status' => 'integer',
    ];

    /**
     * 获取活动参与者
     */
    public function participants()
    {
        return $this->belongsToMany(WechatUser::class, 'lottery_participants')
            ->withTimestamps();
    }

    /**
     * 获取活动获奖者
     */
    public function winners()
    {
        return $this->belongsToMany(WechatUser::class, 'lottery_winners')
            ->withTimestamps()
            ->withPivot('prize_name', 'prize_description');
    }
} 